package com.mingtu.guards.adapter;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.StringUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mingtu.common.utils.MyUtills;
import com.mingtu.guards.R;
import com.mingtu.guards.bean.AirRecordBean;

import java.util.List;

public class AircraftRecordAdapter extends BaseQuickAdapter<AirRecordBean.DataBean.ListBean, BaseViewHolder> {
    private List<AirRecordBean.DataBean.ListBean> mData;
    private OnItemClickListener mOnItemClickListener = null;

    public AircraftRecordAdapter() {
        super(R.layout.item_aircraft_record);
    }


    @Override
    protected void convert(@NonNull BaseViewHolder helper, AirRecordBean.DataBean.ListBean listBean) {
        String beginTime = listBean.getBeginTime();
        String endTime = listBean.getEndTime();
        String duration = listBean.getDuration();
        String mileage = listBean.getMileage();

        if (!StringUtils.isEmpty(beginTime)) {
            helper.setText(R.id.tv_air_start_time, beginTime);
        }
        if (!StringUtils.isEmpty(endTime)) {
            helper.setText(R.id.tv_air_end_time, endTime);
        }
        if (!StringUtils.isEmpty(duration)) {
            long d = 0;
            if (duration.indexOf(".") != -1) {
                String array[] = duration.split("\\.");
                d = Long.parseLong(array[0]);
            } else {
                d = Long.parseLong(duration);
            }
            helper.setText(R.id.tv_air_time, MyUtills.formatSeconds5(d));
        } else {
            helper.setText(R.id.tv_air_time, "0h");
        }
        if (!StringUtils.isEmpty(mileage)) {
            helper.setText(R.id.tv_air_mileage, (mileage + "km"));
        }
    }
}
